package com.lill.system.serivce.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lill.system.dao.ISysUserAppDao;
import com.lill.system.model.SysUserAppEntity;
import com.lill.system.service.ISysUserAppService;

/**
 * 用户与APP对应关系Service实现类
 *
 * @author lill
 * @date 2019-04-08 18:47:17
 */
@Service("userAppService")
public class SysUserAppServiceImpl implements ISysUserAppService {
    @Autowired
    private ISysUserAppDao userAppDao;

    public SysUserAppEntity queryObject(Integer id) {
        return userAppDao.queryObject(id);
    }

    public List<SysUserAppEntity> queryList(Map<String, Object> map) {
        return userAppDao.queryList(map);
    }

    public int queryTotal(Map<String, Object> map) {
        return userAppDao.queryTotal(map);
    }

    public int save(SysUserAppEntity userApp) {
        return userAppDao.save(userApp);
    }

    public int update(SysUserAppEntity userApp) {
        return userAppDao.update(userApp);
    }

    public int delete(Integer id) {
        return userAppDao.delete(id);
    }

    public int deleteBatch(Integer[] ids) {
        return userAppDao.deleteBatch(ids);
    }

	@Override
	public void saveOrUpdate(String userId, List<Integer> appList) {
		if (appList.size() == 0) {
            return;
        }

        //先删除用户与APP关系
		userAppDao.deleteByUserId(userId);

        //保存用户与APP关系
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("userId", userId);
        map.put("appList", appList);
        userAppDao.save(map);
	}

	@Override
	public List<Integer> queryAppIdList(String userId) {
		return userAppDao.queryAppIdList(userId);
	}
}
